home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10170 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: hubcap.clemson.edu!hubcap!mjs
  2. From: mjs@hubcap.clemson.edu (M. J. Saltzman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: NEwbie: How to return a multi-dimensional array from function?
  5. Date: 15 Mar 96 20:53:00 GMT
  6. Organization: Clemson University
  7. Message-ID: <mjs.826923180@hubcap>
  8. References: <4hp273$8bu@news.xs4all.nl> <31404CE9.1A4A@mc.net> <mjs.826298629@hubcap> <4ib78s$6gv@news.bridge.net> <4ic3p3$cl5@news.xs4all.nl> <4ic8pj$c99@news.bridge.net>
  9. NNTP-Posting-Host: hubcap.clemson.edu
  10. X-Newsreader: NN version 6.5.0 #1
  11.  
  12. psycho@bridge.net (Gary Thompson) writes:
  13.  
  14. |falstaff@xs4all.nl (Falstaff) wrote:
  15.  
  16. |>[...]
  17.  
  18. |>If you declare a function
  19.  
  20. |>int *demo(void)
  21. |>{  static int n=0;
  22. |>   n++;
  23. |>   return &n;
  24. |>}
  25.  
  26. |>the caller can use the static variable until the next time your function
  27. |>is called.  This is how the standard library function tmpnam() returns,
  28. |>for example.
  29.  
  30. |Well, of course it will work in your example... you returned the value.  Try
  31. |this...
  32.  
  33. No he didn't.  He returned the *address*.  That's what I did in my original 
  34. response.
  35.  
  36. |main()
  37. |{
  38. |    foo();
  39. |    n++;
  40. |}
  41.  
  42. |foo()
  43. |{
  44. |    static int n=0;
  45. |    n=1;
  46. |}
  47.  
  48. |This will give you a compile error.  You cannot use N outside of foo() which was
  49. |the point I was making.  However, if you called foo again, N will be 1 before it
  50. |get's re-assigned to 1.
  51.  
  52. Of course it will.  But the point you were making is moot, since the
  53. technique I used in the post you responded to was the same as
  54. Falstaff's.
  55. -- 
  56.         Matthew Saltzman
  57.         Clemson University Math Sciences
  58.         mjs@clemson.edu
  59.